import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import EmployeeName from "../pages/EmployeeName.vue";
import EmployeeAttendance from "../pages/EmployeeAttendance.vue";
import EmployeeSalay from "../pages/EmployeeSalary.vue";
import EmployeeEntryList from "../pages/EmployeeEntryList.vue";
import EmployeeConfirmList from "../pages/EmployeeConfirmList.vue";
import EmployeeDimissionList from "../pages/EmployeeDimissionList.vue";
import EmployeeTrainingList from "../pages/EmployeeTrainingList.vue";
import EmployeeChart from "../pages/EmployeeChart.vue";
import LoginPage from "../pages/LoginPage.vue";
import Enterprise from "../pages/Enterprise.vue";
Vue.use(VueRouter);
const router = new VueRouter({
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      component: LoginPage,
    },
    {
      name: "技术",
      path: "/home",
      component: Home,
      redirect: "/EmployeeName",
    },
    {
      path: "/home",
      component: Home,
      name: "人力",
      children: [
        {
          path: "/EmployeeName",
          name: "员工花名",
          component: EmployeeName,
        },
        {
          path: "/EmployeeAttendance",
          name: "员工考勤",
          component: EmployeeAttendance,
        },
        {
          path: "/EmployeeSalay",
          name: "员工工资",
          component: EmployeeSalay,
        },
        {
          path: "/EmployeeEntryList",
          name: "员工入职名单",
          component: EmployeeEntryList,
        },
        {
          path: "/EmployeeConfirmList",
          name: "员工转正名单",
          component: EmployeeConfirmList,
        },
        {
          path: "/EmployeeDimissionList",
          name: "员工离职名单",
          component: EmployeeDimissionList,
        },
        {
          path: "/EmployeeTrainingList",
          name: "员工培训名单",
          component: EmployeeTrainingList,
        },
        {
          path: "/EmployeeChart",
          name: "员工分析图表",
          component: EmployeeChart,
        },
      ],
    },
    {
      name: "后勤",
      path: "/home",
      component: Home,
    },
    {
      name: "企宣",
      path: "/home",
      component: Home,
      children: [
        {
          path: "/Enterprise",
          name: "企宣",
          component: Enterprise,
        },
      ],
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    next();
  }
  if (sessionStorage.getItem("role") === null) {
    next("/login");
  } else {
    next();
  }
});
export default router;
